package com.kitty.game.function.service;

import com.kitty.common.model.Pos;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.bag.controller.flyStateController;
import com.kitty.game.confirm.model.*;
import com.kitty.game.equip.message.RespNotifyMiscEx;
import com.kitty.game.role.model.Role;
import com.kitty.game.equip.model.RoleEquip;
import com.kitty.game.equip.model.RoleEquipField;
import com.kitty.game.config.CustomFasion;
import com.kitty.game.config.Fasion;
import com.kitty.game.config.Medicine;
import com.kitty.game.config.OnlineMall;
import com.kitty.game.config.SpecialItem;
import com.kitty.game.attribute.AttrService;
import com.kitty.game.bag.message.RespStore;
import com.kitty.game.bag.model.StoreEquipInfo;
import com.kitty.game.enter.FiedValue;
import com.kitty.game.enter.RespDisappear;
import com.kitty.game.enter.RespTitle;
import com.kitty.game.equip.service.EquipService;
import com.kitty.game.onlinemall.service.MallService;
import com.kitty.game.role.message.RespAppear;
import com.kitty.game.scene.SceneManager;
import com.kitty.game.shop.ShopDataPool;
import com.kitty.game.team.message.RespConfirm;
import com.kitty.game.team.message.RespMsg;
import com.kitty.game.team.message.RespSetVisiblePet;
import com.kitty.game.utils.Const;
import com.kitty.game.waiguan.*;
import com.kitty.mina.cache.DataCache;
import com.kitty.mina.cache.SessionUtils;
import com.kitty.mina.message.Message;
import com.kitty.mina.message.MessagePusher;
import com.kitty.game.fight.service.BroadcastService;
import com.kitty.game.role.service.RoleService;
import org.apache.mina.core.session.IoSession;
import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.nutz.lang.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class FasionService {
    Logger logger = LoggerFactory.getLogger(FasionService.class);
    @Autowired
    AttrService attrService;
    @Autowired
    EquipService equipService;
    @Autowired
    MallService mallService;
    @Autowired
    BroadcastService broadcastService;
    @Autowired
    RoleService roleService;


    /**
     * 发送空列表
     */

    public void sendNullStore(IoSession session, String type, short min, short max) {
        RespStore respStore = new RespStore();
        respStore.setStr(type);//时装"fasion_store"
        List<StoreEquipInfo> list = new ArrayList<>();
        for (short i = min; i <= max; i++) {
            StoreEquipInfo storeEquipInfo = new StoreEquipInfo();
            storeEquipInfo.setPos(i);
            list.add(storeEquipInfo);
        }
        respStore.setList(list);
        MessagePusher.pushMessage(session, respStore);
    }


    /**
     * 时装使用 存入时装仓库
     *
     * @param pos
     * @param role
     * @param roleEquip
     */
    public void sendFasionStore(short pos, Role role, RoleEquip roleEquip, String type) {
        RespStore respStore = new RespStore();
        respStore.setStr(type);
        ArrayList<StoreEquipInfo> arrayList = new ArrayList<>();
        respStore.setList(arrayList);
        StoreEquipInfo storeEquipInfo = new StoreEquipInfo();
        storeEquipInfo.setPos(pos);
        arrayList.add(storeEquipInfo);
        storeEquipInfo.setPos(roleEquip.getPosition());
        storeEquipInfo.setEquipFields(equipService.transferList(roleEquip.getFields()), equipService.transferList2(roleEquip.getHunQiFields()));
        MessagePusher.pushMessage(role, respStore);
    }

    /**
     * 取空位
     *
     * @param role
     * @return
     */
    public short getFasionPos(Role role, String type) {
        short min = 0, max = 0;
        if (type.equals("fasion_store")) {
            min = 4001;
            max = 4050;
        } else if (type.equals("effect_store")) {
            min = 4501;
            max = 4510;
        } else if (type.equals("custom_store")) {
            min = 5001;
            max = 5200;
        } else if (type.equals("follow_pet_store")) {
            min = 5201;
            max = 5250;
        }else if(type.equals("team_icon_store")){
            min = 5299 ;
            max = 5340;
        }
        for (short i = min; i < max; i++) {
            RoleEquip roleEquip = equipService.getRoleEquipByPos(role, i);
            if (roleEquip == null) {
                return i;
            }
        }
        return -1;
    }

    /**
     * 类型取时装列表
     */
    public ArrayList<FasionInfo> getFasionList(int type) {
        ArrayList<FasionInfo> arrayList = new ArrayList<>();
        DataCache.NAME_FASION.forEach((name, fasion) -> {
            if (fasion.getType() == type && !fasion.getName().contains("万道")) {
                FasionInfo fasionInfo = new FasionInfo();
                fasionInfo.setFasionName(fasion.getName());
                fasionInfo.setPrice(fasion.getPrice());
                arrayList.add(fasionInfo);
            }
        });
        return arrayList;
    }

    public boolean useFasion(RoleEquip roleEquip, IoSession session) {
        Fasion fasion = DataCache.NAME_FASION.get(roleEquip.getName());
        if (fasion != null && (fasion.getType() == 1 || fasion.getName().contains("万道"))) {
            addFasion(session, roleEquip);
            return true;
        }
        OnlineMall onlineMall = mallService.getOnlineMallByName(roleEquip.getName());
        if (onlineMall != null && onlineMall.getItemtype() == 25) {
            addFasion(session, roleEquip);
            return true;
        }
        return false;
    }

    /**
     * 穿时装
     *
     * @param session
     * @param name
     */
    public void equipFasion(IoSession session, String name) {
        Role role = SessionUtils.getRoleBySession(session);
        RoleEquip roleEquip = null;
        String type = "";
        for (Map.Entry<Integer, RoleEquip> entry : role.getEquipBox().getEquips().entrySet()) {
            RoleEquip tempEquip = entry.getValue();
            if (tempEquip.getPosition() >= 4001 && tempEquip.getPosition() <= 4050 && tempEquip.getName().contains(name)) {
                roleEquip = tempEquip;
                type = "fasion";
                break;
            }
            if (tempEquip.getPosition() >= 5201 && tempEquip.getPosition() <= 5250 && tempEquip.getName().contains(name)) {
                roleEquip = tempEquip;
                type = "followPet";
                break;
            }
            if (tempEquip.getPosition() >= 4501 && tempEquip.getPosition() <= 4510 && tempEquip.getName().contains(name)) {
                roleEquip = tempEquip;
                type = "effect";
                break;
            }
            if (tempEquip.getPosition() >= 5299 && tempEquip.getPosition() <= 5340 && tempEquip.getName().contains(name)) {
                roleEquip = tempEquip;
                type = "teamIcom";
                System.out.println("teamIcom");
                break;
            }
        }
        if (roleEquip == null) {
            return;
        }
        if (type.equals("fasion")) {
            //穿上 需要判断时装位置有没有已穿戴时装
            unEquipCustomFasion(role, (short) 31, false);//卸下之前时装
            sendNullFasion(session, roleEquip, "fasion_store");
            roleEquip.setPosition((short) 31);

            equipService.refreshRoleEquip(role,roleEquip);

            int icon, fasionIcon;
            icon = attrService.getValue(roleEquip.getFields().get((short) 1).getField().get((short) 40).getValue());
            fasionIcon = DataCache.ICON_FASION.get(icon);
            if(name.contains("万道")){
                int effectIcon = SpringUtils.getBean(flyStateController.class).getEffectByName(name);
                role.getPropsStatus().setv("wandan_effect",effectIcon);
                role.setEffectIcon(effectIcon);
            }
            role.setFasionIcon(fasionIcon);
            role.save();
            broadcastService.sendUpdateAppear(role);
            MessagePusher.pushMessage(session, new RespMsg("穿戴成功！"));

            RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
            respFasionCustomEnd.setLabel("equip_fasion");
            MessagePusher.pushMessage(session, respFasionCustomEnd);
        } else if (type.equals("followPet")) {
            unEquipCustomFasion(role, (short) 37, false);
            sendNullFasion(session, roleEquip, "follow_pet_store");//发送空位置

            roleEquip.setPosition((short) 37);

            equipService.refreshRoleEquip(role,roleEquip);

            broadcastFollowPet(role, roleEquip);

            RespTitle respTitle = new RespTitle();
            respTitle.setRoleId(roleEquip.getId());
            MessagePusher.pushMessage(session, respTitle);

            RespSetVisiblePet respSetVisiblePet = new RespSetVisiblePet();
            respSetVisiblePet.setId(roleEquip.getId());
            MessagePusher.pushMessage(session, respSetVisiblePet);

            RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
            respFasionCustomEnd.setLabel("equip_fasion");
            MessagePusher.pushMessage(session, respFasionCustomEnd);
        } else if (type.equals("effect")) {
            unEquipCustomFasion(role, (short) 32, false);//卸下之前时装

            sendNullFasion(session, roleEquip, "effect_store");
            roleEquip.setPosition((short) 32);

            equipService.refreshRoleEquip(role,roleEquip);

            int icon, fasionIcon;
            icon = attrService.getValue(roleEquip.getFields().get((short) 1).getField().get((short) 40).getValue());
            fasionIcon = DataCache.ICON_FASION.get(icon);
            role.setEffectIcon(fasionIcon);
            role.save();
            broadcastService.sendUpdateAppear(role);
            MessagePusher.pushMessage(session, new RespMsg("穿戴成功！"));

            RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
            respFasionCustomEnd.setLabel("equip_fasion");
            MessagePusher.pushMessage(session, respFasionCustomEnd);
        }else if (type.equals("teamIcom")){
            unEquipCustomFasion(role, (short) 39, false);//卸下之前时装

            sendNullFasion(session, roleEquip, "team_icon_store");
            roleEquip.setPosition((short) 39);

            equipService.refreshRoleEquip(role,roleEquip);

            int icon, fasionIcon;
            icon = attrService.getValue(roleEquip.getFields().get((short) 1).getField().get((short) 40).getValue());
            fasionIcon = DataCache.ICON_FASION.get(icon);
            role.getPropsStatus().setv("duibiao_icon", fasionIcon);
            broadcastService.sendUpdateAppear(role);

            MessagePusher.pushMessage(session, new RespMsg("穿戴成功！"));

            RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
            respFasionCustomEnd.setLabel("equip_fasion");
            MessagePusher.pushMessage(session, respFasionCustomEnd);
        }

        role.save();
    }

    /**
     * 广播跟宠
     */
    private void broadcastFollowPet(Role role, RoleEquip roleEquip) {
        SceneManager.INSTANCE.sendMessages(role,getFollowPetMessage(role, roleEquip));
    }


    private Message getFollowPetMessage(Role role, RoleEquip roleEquip) {
        Pos position = role.getPos();
        int icon, fasionIcon;
        icon = attrService.getValue(roleEquip.getFields().get((short) 1).getField().get((short) 40).getValue());
        fasionIcon = DataCache.ICON_FASION.get(icon);
        RespAppear respAppear = new RespAppear();
        respAppear.setRoleId(roleEquip.getId());
        respAppear.setPosX(position.getX());
        respAppear.setPosY(position.getY());
        respAppear.setDir(position.getDir());
        respAppear.setStatus(fasionIcon);
        respAppear.setIcon(fasionIcon);
        respAppear.setRoleName("");
        respAppear.setLevel((short) 0);
        respAppear.setSpecial_icon(0);
        respAppear.setType((short) Const.PET);
        respAppear.setSub_type(2);
        respAppear.setOwner_id(role.getRoleId());
        respAppear.setPortrait(fasionIcon);
        respAppear.setOrg_icon(fasionIcon);
        respAppear.setLeaderId(role.getRoleId());
        respAppear.setGid("");
        respAppear.setWeaponId(0);
        return respAppear;

    }

    /**
     * 消失跟宠
     */
    public void broadcastDisappear(Role role, int id) {
        SceneManager.INSTANCE.sendMessages(role,new RespDisappear(id,Const.PET));
    }


    private void sendNullFasion(IoSession session, RoleEquip roleEquip, String type) {
        RespChuanFasion respChuanFasion = new RespChuanFasion();
        respChuanFasion.setType(type);
        respChuanFasion.setPos(roleEquip.getPosition());
        respChuanFasion.setUse((byte) 0);
        MessagePusher.pushMessage(session, respChuanFasion);
    }

    /**
     * 卸下时装
     *
     * @param role
     * @param fasionPos
     */
    public void unEquipCustomFasion(Role role, short fasionPos, boolean isUnEquip) {
        RoleEquip roleEquip = equipService.getRoleEquipByPos(role,fasionPos);
        if (roleEquip == null) {
            return;
        }

        if (roleEquip.getPosition() == 31) {//卸下时装
            short pos = getFasionPos(role, "fasion_store");
            if (pos != -1) {
                equipService.setPositionNull(role, (byte) roleEquip.getPosition());//先卸下
                roleEquip.setPosition(pos);
                sendFasionStore(roleEquip.getPosition(), role, roleEquip, "fasion_store");

                role.setFasionIcon(0);
                role.save();
                broadcastService.sendUpdateAppear(role);
                if (isUnEquip) {
                    MessagePusher.pushMessage(role, new RespMsg("卸下成功！"));
                }


                RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
                respFasionCustomEnd.setLabel("unequip_fasion");
                MessagePusher.pushMessage(role, respFasionCustomEnd);
            }
        } else if (roleEquip.getPosition() == 37) {//卸下跟宠
            short pos = getFasionPos(role, "follow_pet_store");
            if (pos != -1) {
                equipService.setPositionNull(role, (byte) roleEquip.getPosition());//先卸下
                roleEquip.setPosition(pos);
                sendFasionStore(roleEquip.getPosition(), role, roleEquip, "follow_pet_store");

                broadcastDisappear(role, roleEquip.getId());
                if (isUnEquip) {
                    MessagePusher.pushMessage(role, new RespMsg("卸下成功,#R" + roleEquip.getName() + "#n不再跟随你了！"));
                }
                RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
                respFasionCustomEnd.setLabel("unequip_fasion");
                MessagePusher.pushMessage(role, respFasionCustomEnd);
            }
        } else if (roleEquip.getPosition() == 32) {//卸下特效
            short pos = getFasionPos(role, "effect_store");
            if (pos != -1) {
                equipService.setPositionNull(role, (byte) roleEquip.getPosition());//先卸下
                roleEquip.setPosition(pos);
                sendFasionStore(roleEquip.getPosition(), role, roleEquip, "effect_store");

                broadcastDisappear(role, roleEquip.getId());
                if (isUnEquip) {
                    MessagePusher.pushMessage(role, new RespMsg("卸下成功！"));
                }
                RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
                respFasionCustomEnd.setLabel("unequip_fasion");
                MessagePusher.pushMessage(role, respFasionCustomEnd);
            }
        } else if (roleEquip.getPosition() == 33 || roleEquip.getPosition() == 34 || roleEquip.getPosition() == 35 || roleEquip.getPosition() == 36 ||roleEquip.getPosition() == 38) {
            short pos = getFasionPos(role, "custom_store");
            if (pos != -1) {
                equipService.setPositionNull(role, (byte) roleEquip.getPosition());//先卸下
                roleEquip.setPosition(pos);
                sendFasionStore(roleEquip.getPosition(), role, roleEquip, "custom_store");

                role.setCustomFasion("");
                role.save();
                broadcastService.sendUpdateAppear(role);

                if (isUnEquip) {
                    MessagePusher.pushMessage(role, new RespMsg("卸下成功！"));
                }
                RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
                respFasionCustomEnd.setLabel("unequip_fasion");
                MessagePusher.pushMessage(role, respFasionCustomEnd);
            }
        }else if (roleEquip.getPosition() == 39) {//卸下特效
            short pos = 0 ;
            if(roleEquip.getName().equals("问道情")){
                pos = 5299 ;
            }else if(roleEquip.getName().equals("八卦阵")){
                pos = 5300 ;
            }else if(roleEquip.getName().equals("吉祥结")){
                pos = 5301 ;
            }else if(roleEquip.getName().equals("星辰奇缘")){
                pos = 5302 ;
            }else if(roleEquip.getName().equals("月亮之上")){
                pos = 5303 ;
            }else if(roleEquip.getName().equals("大风车")){
                pos = 5304 ;
            }else if(roleEquip.getName().equals("归来兮")){
                pos = 5305 ;
            }

            if(pos == 0){
                return;
            }
//            short pos = getFasionPos(role, "team_icon_store");
            if (pos != -1) {
                equipService.setPositionNull(role, (byte) roleEquip.getPosition());//先卸下
                roleEquip.setPosition(pos);
                sendFasionStore(roleEquip.getPosition(), role, roleEquip, "team_icon_store");

                broadcastDisappear(role, roleEquip.getId());
                if (isUnEquip) {
                    MessagePusher.pushMessage(role, new RespMsg("卸下成功！"));
                }
                RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
                respFasionCustomEnd.setLabel("unequip_fasion");
                MessagePusher.pushMessage(role, respFasionCustomEnd);
            }
        }

        role.save();
    }


    /**
     * 购买时装
     *
     * @param session
     * @param reqBuyFasion
     */
    public void buyFasion(IoSession session, ReqBuyFasion reqBuyFasion) {
        Role role = SessionUtils.getRoleBySession(session);
        if(role==null){
            return;
        }
        if (reqBuyFasion.getName().contains("|")) {

            if (reqBuyFasion.isBuy()) { //购买
                logger.info("购买自定义");
                List<Fasion> list = new ArrayList<>();
                int needGold = 0;
                StringBuilder msg = new StringBuilder();
                String[] names = reqBuyFasion.getName().split("\\|");
                for (String name : names) {
                    Fasion fasion = getFasionInfo(name);
                    RoleEquip roleEquip = equipService.getRoleEquipByName(session, name);
                    if (roleEquip == null) {
                        list.add(fasion);
                        needGold += fasion.getPrice();
                        msg.append("#R").append(fasion.getName()).append("#n消费#R").append(fasion.getPrice()).append("#n元宝、");
                    }
                }
                msg = new StringBuilder("确认花费#R" + needGold + "#n元宝进行换装吗？其中" + msg.substring(0, msg.length() - 1));
                RespConfirm respConfirm = new RespConfirm();
                respConfirm.setTips(msg.toString());
                MessagePusher.pushMessage(session, respConfirm);

                role.setConfirm(new BuyCustomFashionConfirm(needGold,list));

                RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
                respFasionCustomEnd.setLabel("equip_multi_fasion");
                MessagePusher.pushMessage(session, respFasionCustomEnd);
            } else {//穿戴?
                String[] names = reqBuyFasion.getName().split("\\|");
                ArrayList<CustomFasion> arrayList = new ArrayList<>();
                for (String name : names) {
                    CustomFasion customFasion = mallService.getCustomFashion(name);
                    arrayList.add(customFasion);
                    RoleEquip roleEquip = equipService.getRoleEquipByName(session, name);
                    logger.info("自定义时装=={}==={}", Json.toJson(customFasion, JsonFormat.compact()), roleEquip.getName());
                    unEquipCustomFasion(role, (short) customFasion.getPos(), false);//卸下之前时装
                    sendNullFasion(session, roleEquip, "custom_store");

                    roleEquip.setPosition(customFasion.getPos());
                    equipService.refreshRoleEquip(role, roleEquip);
                }
                String customFasionIcon = getCustomFasionIcon(arrayList);
                logger.info("custom=={}", customFasionIcon);
                role.setCustomFasion(customFasionIcon);
                role.save();
                broadcastService.sendUpdateAppear(role);
                MessagePusher.pushMessage(session, new RespMsg("换装成功！"));

                RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
                respFasionCustomEnd.setLabel("equip_fasion");
                MessagePusher.pushMessage(session, respFasionCustomEnd);
            }

        } else {
            Fasion fasion = getFasionInfo(reqBuyFasion.getName());
            if (fasion == null) {
                return;
            }
            String msg = "确认花费#R" + fasion.getPrice() + "#n元宝购买#R" + fasion.getName() + "#n吗？";
            RespConfirm respConfirm = new RespConfirm();
            respConfirm.setTips(msg);
            MessagePusher.pushMessage(session, respConfirm);

            role.setConfirm(new BuyFashionConfirm(fasion));

            RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
            respFasionCustomEnd.setLabel("buy_fasion");
            MessagePusher.pushMessage(session, respFasionCustomEnd);
        }

    }

    /**
     * 取自定义时装外观
     */
    public String getCustomFasionIcon(ArrayList<CustomFasion> arrayList) {
        if (arrayList.size() < 4) {
            return "";
        }
        /** return string.format("%02d%02d%02d%02d%02d%02d%02d%02d%02d%02d", weaponIndex, backIndex, hairIndex, bodyIndex, trousersIndex, bodyIndex, bodyIndex, hairIndex, backIndex, weaponIndex)*/
        /**return string.format("%02d%02d%02d%02d%02d%02d%02d%02d%02d%02d%02d", nudeIndex, weaponIndex, backIndex, hairIndex, bodyIndex, trousersIndex, bodyIndex, bodyIndex, hairIndex, backIndex, weaponIndex)*/
        int head = 0, clothes = 0, trousers = 0, weapon = 0,back=0, headColor = 0, clothesColor = 0, trousersColor = 0, weaponColor = 0,backColor=0;
        for (CustomFasion customFasion : arrayList) {
            if (customFasion.getPos() == 33) {
                head = customFasion.getType();
                headColor = customFasion.getColor();
            } else if (customFasion.getPos() == 34) {
                clothes = customFasion.getType();
                clothesColor = customFasion.getColor();
            } else if (customFasion.getPos() == 35) {
                trousers = customFasion.getType();
                trousersColor = customFasion.getColor();
            } else if (customFasion.getPos() == 36) {
                weapon = customFasion.getType();
                weaponColor = customFasion.getColor();
            }else if(customFasion.getPos() == 38){
                back = customFasion.getType();
                backColor = customFasion.getColor();
            }
        }
        return makePartString(back,head,clothes,trousers,weapon)+":"+makePartColorString(0,backColor,headColor,clothesColor,trousersColor,weaponColor);
    }

    /**部件*/
    private String makePartString(int backIndex,int hairIndex,int bodyIndex,int trousersIndex,int weaponIndex){
        return String.format("%02d%02d%02d%02d%02d%02d%02d%02d%02d%02d",weaponIndex, backIndex, hairIndex, bodyIndex, trousersIndex, bodyIndex, bodyIndex, hairIndex, backIndex, weaponIndex);
    }


    /** 生成换色字符串*/
    private String makePartColorString(int nudeIndex ,int backIndex,int hairIndex,int bodyIndex,int trousersIndex,int weaponIndex){
        return String.format("%02d%02d%02d%02d%02d%02d%02d%02d%02d%02d%02d",nudeIndex, weaponIndex, backIndex, hairIndex, bodyIndex, trousersIndex, bodyIndex, bodyIndex, hairIndex, backIndex, weaponIndex);
    }


    private void getFollowPet(RoleEquip roleEquip, OnlineMall onlineMall, int num) {
        SpecialItem specialItem = null;
        if (onlineMall.getName().contains("·")) {
            String[] strings = onlineMall.getName().split("·");
            specialItem = mallService.getSpecialItem(strings[0]);
        } else {
            specialItem = mallService.getSpecialItem(onlineMall.getName());
        }
        if (specialItem == null) {
            specialItem = new SpecialItem();

            Medicine medicine = ShopDataPool.getMedicineBy(onlineMall.getName());
            if (medicine != null) {
                specialItem.setIcon(medicine.getIcon());
            } else {
                specialItem.setIcon(1001);
            }

        }
        if (Strings.isEmpty(specialItem.getColor())) {
            specialItem.setColor("金色");
        }
        RoleEquipField roleEquipField = new RoleEquipField();
        roleEquipField.setType((short) 1);
        roleEquipField.setField(new LinkedHashMap<>());
        roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 89);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue("");
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 264);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue("");
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 205);//性别要求
            fiedValue.setVT((byte) 6);
            fiedValue.setValue((byte) 0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 306);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue(roleEquip.getId() + "");//"5933997D5DCD40014D01"
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 1);//名称
            fiedValue.setVT((byte) 4);
            String[] strings = {};
            if (onlineMall.getName().contains("天")) {
                strings = onlineMall.getName().split("·");
                fiedValue.setValue(strings[0]);
            } else {
                fiedValue.setValue(onlineMall.getName());
            }
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 261);
            fiedValue.setVT((byte) 2);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 206);//使用方式  69380
            fiedValue.setVT((byte) 3);
            if (onlineMall.getType() != 0) {
                fiedValue.setValue(onlineMall.getType());
            } else {
                fiedValue.setValue(69380);
            }
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 38);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 74);//物品类型 24
            fiedValue.setVT((byte) 7);
            fiedValue.setValue(onlineMall.getItemtype());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 34);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 84);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(roleEquip.getId());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 209);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue("");
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 270);//限制交易
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 41);
            fiedValue.setVT((byte) 7);
            fiedValue.setValue(8);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 203);// 叠加数量
            fiedValue.setVT((byte) 2);
            fiedValue.setValue((short) num);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 40);// 背包中的图标
            fiedValue.setVT((byte) 7);
            fiedValue.setValue((short) specialItem.getIcon());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 215);//
            fiedValue.setVT((byte) 6);
            fiedValue.setValue((byte) 0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 887);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 3001);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue(onlineMall.getName());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 348);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 282);
            fiedValue.setVT((byte) 2);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 207);//出售价格
            fiedValue.setVT((byte) 3);
            fiedValue.setValue((short) 500);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
    }

    /**
     * 购买跟宠
     */
    private RoleEquip getFollowPet(Role role, OnlineMall onlineMall, int num) {
        RoleEquip roleEquip = new RoleEquip();
        roleEquip.setId(mallService.getRoleEquipId());


        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setPosition((short) 0);
        roleEquip.setName(onlineMall.getName());
        roleEquip.setFields(new LinkedHashMap<>());
        {
            getFollowPet(roleEquip, onlineMall, num);
        }
        roleEquip.setType("跟宠");
//

        return roleEquip;
    }

    /**
     * 名称取Fasion
     */
    private Fasion getFasionInfo(String name) {
        return DataCache.NAME_FASION.get(name);
    }

    /**
     * 获得时装
     */
    public RoleEquip getFasion(Role role, String name, int itemNum, boolean isGold) {
        OnlineMall onlineMall = new OnlineMall();
        onlineMall.setName(name);
        onlineMall.setType(2097924);
        onlineMall.setItemtype((short) 25);
        return getFashion(role, onlineMall, itemNum, isGold);
    }

    /**
     * 获得时装
     */
    public RoleEquip getCustomFasion(Role role, String name, int itemNum, boolean isGold) {
        OnlineMall onlineMall = new OnlineMall();
        onlineMall.setName(name);
        onlineMall.setType(69380);
        onlineMall.setItemtype((short) 25);
        return getCustomFashion(role, onlineMall, itemNum, isGold);
    }

    /**
     * 获得时装
     */
    public RoleEquip getFollowPet(Role role, String name, int itemNum, boolean isGold) {
        OnlineMall onlineMall = new OnlineMall();
        onlineMall.setName(name);
        onlineMall.setType(69380);
        onlineMall.setItemtype((short) 24);
        return getFollowPet(role, onlineMall, itemNum);
    }

    /**
     * 时装使用叠加
     */
    private void addFasion(IoSession session, RoleEquip fasionEquip) {
        Role role = SessionUtils.getRoleBySession(session);
        RoleEquip roleEquip = null;
        boolean isExist = false;
        for (Map.Entry<Integer, RoleEquip> entry : role.getEquipBox().getEquips().entrySet()) {
            roleEquip = entry.getValue();
            if ((roleEquip.getPosition() >= 4001 && roleEquip.getPosition() <= 4050) || roleEquip.getPosition() == 31) {
                short roleEquipIcon = attrService.getValue(roleEquip.getFields().get((short) 1).getField().get((short) 40).getValue()).shortValue();
                short fasionIcon = attrService.getValue(fasionEquip.getFields().get((short) 1).getField().get((short) 40).getValue()).shortValue();
                if (roleEquipIcon == fasionIcon) {//已有同名时装
                    isExist = true;
                    break;
                }
            }
        }
        if (isExist) {
            int oldtime = attrService.getValue(roleEquip.getFields().get((short) 1).getField().get((short) 887).getValue());
            if (roleEquip.getName().contains("限时") && fasionEquip.getName().contains("天")) {
                String[] strings = fasionEquip.getName().split("·");
                int day = Integer.parseInt(strings[1].split("天")[0]);
                int time = new Long(oldtime + day * 86400).intValue();
                roleEquip.setName(strings[0] + "·限时");
                roleEquip.getFields().get((short) 1).getField().get((short) 3001).setValue(strings[0] + "·限时");
                roleEquip.getFields().get((short) 1).getField().get((short) 887).setValue(time);
                MessagePusher.pushMessage(session, new RespMsg("你的#Y" + roleEquip.getName() + "#n增加了#R" + day + "#n天时间。"));
            } else if (roleEquip.getName().contains("限时") && fasionEquip.getName().contains("永久")) {
                roleEquip.setName(fasionEquip.getName());
                roleEquip.getFields().get((short) 1).getField().get((short) 3001).setValue(fasionEquip.getName());
                roleEquip.getFields().get((short) 1).getField().get((short) 887).setValue(0);
                MessagePusher.pushMessage(session, new RespMsg("你已永久拥有#R" + roleEquip.getName() + "#n时装。"));
            } else if (roleEquip.getName().contains("永久")) {
                MessagePusher.pushMessage(session, new RespMsg("你已永久拥有#R" + roleEquip.getName() + "#n时装，无法叠加时间。"));
                return;
            }
            equipService.delRoleEquip(fasionEquip, role);
            if (roleEquip.getPosition() == 31) {
                equipService.refreshRoleEquip(role,roleEquip);
            } else {
                sendFasionStore(roleEquip.getPosition(), role, roleEquip, "fasion_store");
                //SpringUtils.getBean(BuyFashionConfirmHandler.class).useFasion(role,0,fasionEquip.getName());
            }

        } else {
            short pos = getFasionPos(role, "fasion_store");
            if (pos != -1) {
                equipService.setPositionNull(role, (byte) fasionEquip.getPosition());//消失背包时装
                fasionEquip.setPosition(pos);
                MessagePusher.pushMessage(session, new RespMsg("#R" + fasionEquip.getName() + "#n已放入外观界面中。"));
                if (fasionEquip.getName().endsWith("天")) {
                    String[] strings = fasionEquip.getName().split("·");
                    int day = Integer.parseInt(strings[1].split("天")[0]);
                    int time = new Long(new Date().getTime() / 1000 + day * 86400).intValue();
                    fasionEquip.setName(strings[0] + "·限时");
                    fasionEquip.getFields().get((short) 1).getField().get((short) 3001).setValue(strings[0] + "·限时");
                    fasionEquip.getFields().get((short) 1).getField().get((short) 887).setValue(time);
                }
                role.save();
                sendFasionStore(pos, role, fasionEquip, "fasion_store");
                //商城购买万道袍
//                equipService.delRoleEquip(fasionEquip, role);
//                SpringUtils.getBean(BuyFashionConfirmHandler.class).useFasion(role);
            }
        }
    }

    public void buyFollowPet(IoSession session, ReqBuyFollowPet reqBuyFollowPet) {
        Role role =SessionUtils.getRoleBySession(session);
        Fasion fasion = getFasionInfo(reqBuyFollowPet.getName());
        if (fasion == null) {
            return;
        }
        String msg = "确认花费#R" + fasion.getPrice() + "#n元宝购买#R" + fasion.getName() + "#n吗？";
        RespConfirm respConfirm = new RespConfirm();
        respConfirm.setTips(msg);
        MessagePusher.pushMessage(session, respConfirm);

        role.setConfirm(new BuyFollowPetConfirm(fasion));

        RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
        respFasionCustomEnd.setLabel("buy_follow_pet");
        MessagePusher.pushMessage(session, respFasionCustomEnd);
    }

    /**
     * 购买特效
     *
     * @param session
     * @param reqBuyEffect
     */
    public void buyEffect(IoSession session, ReqBuyEffect reqBuyEffect) {
        Role role = SessionUtils.getRoleBySession(session);
        Fasion fasion = getFasionInfo(reqBuyEffect.getName());
        if (fasion == null) {
            return;
        }

        String msg = "确认花费#R" + fasion.getPrice() + "#n元宝购买#R" + fasion.getName() + "#n吗？";
        RespConfirm respConfirm = new RespConfirm();
        respConfirm.setTips(msg);
        MessagePusher.pushMessage(session, respConfirm);

        role.setConfirm(new BuyEffectConfirm(fasion));

        RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
        respFasionCustomEnd.setLabel("buy_fasion_effect");
        MessagePusher.pushMessage(session, respFasionCustomEnd);
    }

    /**
     * 获得特效
     */
    public RoleEquip getFasionEffect(Role role, String name, int itemNum, boolean isGold) {
        OnlineMall onlineMall = new OnlineMall();
        onlineMall.setName(name);
        onlineMall.setType(262);
        onlineMall.setItemtype((short) 23);
        return getFashion(role, onlineMall, itemNum, isGold);
    }

    private void getFasion(RoleEquip roleEquip, OnlineMall onlineMall, int num, boolean isGold) {
        SpecialItem specialItem = null;
        byte type = 2;
        if (onlineMall.getName().contains("·")) {
            String[] strings = onlineMall.getName().split("·");
            if(strings[0].contains("万道")){
                type=3;
                specialItem = mallService.getSpecialItem(onlineMall.getName());
            }else{
                specialItem = mallService.getSpecialItem(strings[0]);
            }
        } else {
            specialItem = mallService.getSpecialItem(onlineMall.getName());
        }
        if (Strings.isEmpty(specialItem.getColor())) {
            specialItem.setColor("金色");
        }
        RoleEquipField roleEquipField = new RoleEquipField();
        roleEquipField.setType((short) 1);
        roleEquipField.setField(new LinkedHashMap<>());
        roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 89);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue("");
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 205);
            fiedValue.setVT((byte) 6);
            fiedValue.setValue((byte) specialItem.getSex());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 261);
            fiedValue.setVT((byte) 2);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 206);//使用方式
            fiedValue.setVT((byte) 3);
            if (onlineMall.getType() != 0) {
                fiedValue.setValue(onlineMall.getType());
            } else {
                fiedValue.setValue(0);
            }
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 74);//物品类型
            fiedValue.setVT((byte) 7);
            fiedValue.setValue(onlineMall.getItemtype());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 34);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 44);//
            fiedValue.setVT((byte) 2);
            fiedValue.setValue((short) 0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 202);//
            fiedValue.setVT((byte) 6);
            fiedValue.setValue((byte) 16);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 40);// 背包中的图标
            fiedValue.setVT((byte) 7);
            fiedValue.setValue((short) specialItem.getIcon());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 215);//
            fiedValue.setVT((byte) 6);
            fiedValue.setValue((byte) 0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 348);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(2592000);//有可能是时装外观
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 207);//出售价格
            fiedValue.setVT((byte) 3);
            fiedValue.setValue((short) 500);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 264);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue("");
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 1);//名称
            fiedValue.setVT((byte) 4);
            String[] strings = {};
            if (onlineMall.getName().contains("天")) {
                strings = onlineMall.getName().split("·");
                fiedValue.setValue(strings[0]);
            } else {
                fiedValue.setValue(onlineMall.getName());
            }
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 306);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue(roleEquip.getId() + "");//"5933997D5DCD40014D01"
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 38);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 209);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue(specialItem.getColor());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 84);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(roleEquip.getId());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 349);
            fiedValue.setVT((byte) 1);
            fiedValue.setValue((byte) type);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 270);//限制交易
            fiedValue.setVT((byte) 3);
            if (isGold) {
                fiedValue.setValue(0);
            } else {
                fiedValue.setValue(2);
            }
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 203);// 叠加数量
            fiedValue.setVT((byte) 2);
            fiedValue.setValue((short) num);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 41);
            fiedValue.setVT((byte) 7);
            fiedValue.setValue(8);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 3001);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue(onlineMall.getName());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 887);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 29);//性别
            fiedValue.setVT((byte) 1);
            fiedValue.setValue(specialItem.getSex());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 282);
            fiedValue.setVT((byte) 2);
            fiedValue.setValue(2);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
    }

    /**
     * 购买时装
     *
     * @param role
     * @param onlineMall
     * @param num
     * @param isGold
     * @return
     */
    private RoleEquip getFashion(Role role, OnlineMall onlineMall, int num, boolean isGold) {
        RoleEquip roleEquip = new RoleEquip();
        roleEquip.setId(mallService.getRoleEquipId());
        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setPosition((short) 0);
        roleEquip.setName(onlineMall.getName());
        roleEquip.setFields(new LinkedHashMap<>());
        getFasion(roleEquip, onlineMall, num, isGold);
        roleEquip.setType("时装");
        return roleEquip;
    }

    private void getCustomFashion(RoleEquip roleEquip, OnlineMall onlineMall, int num, boolean isGold) {
        CustomFasion customFasion = mallService.getCustomFashion(onlineMall.getName());
        RoleEquipField roleEquipField = new RoleEquipField();
        roleEquipField.setType((short) 1);
        roleEquipField.setField(new LinkedHashMap<>());
        roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 89);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue("");
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 205);
            fiedValue.setVT((byte) 6);
            fiedValue.setValue((byte) 1);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 261);
            fiedValue.setVT((byte) 2);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 206);//使用方式
            fiedValue.setVT((byte) 3);
            if (onlineMall.getType() != 0) {
                fiedValue.setValue(onlineMall.getType());
            } else {
                fiedValue.setValue(0);
            }
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 74);//物品类型
            fiedValue.setVT((byte) 7);
            fiedValue.setValue(onlineMall.getItemtype());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 34);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 44);//
            fiedValue.setVT((byte) 2);
            fiedValue.setValue((short) 0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 202);//
            fiedValue.setVT((byte) 6);
            fiedValue.setValue((byte) 16);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 40);// 背包中的图标
            fiedValue.setVT((byte) 7);
            fiedValue.setValue((short) customFasion.getIcon());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 215);//
            fiedValue.setVT((byte) 6);
            fiedValue.setValue((byte) 0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 348);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(2592000);//有可能是时装外观
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 207);//出售价格
            fiedValue.setVT((byte) 3);
            fiedValue.setValue((short) 500);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 264);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue("");
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 1);//名称
            fiedValue.setVT((byte) 4);
            fiedValue.setValue(onlineMall.getName());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 306);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue(roleEquip.getId() + "");//"5933997D5DCD40014D01"
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 38);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 209);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue("金色");
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 84);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(roleEquip.getId());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 349);
            fiedValue.setVT((byte) 1);
            fiedValue.setValue((byte) 2);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 270);//限制交易
            fiedValue.setVT((byte) 3);
            if (isGold) {
                fiedValue.setValue(0);
            } else {
                fiedValue.setValue(2);
            }
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 203);// 叠加数量
            fiedValue.setVT((byte) 2);
            fiedValue.setValue((short) num);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 41);
            fiedValue.setVT((byte) 7);
            fiedValue.setValue(8);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 3001);
            fiedValue.setVT((byte) 4);
            fiedValue.setValue(onlineMall.getName());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 887);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(0);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 29);//性别
            fiedValue.setVT((byte) 1);
            fiedValue.setValue(customFasion.getSex());
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
        {
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 282);
            fiedValue.setVT((byte) 2);
            fiedValue.setValue(Const.ITEM_COMBINED_EX);
            roleEquipField.getField().put(fiedValue.getType(), fiedValue);
        }
    }

    /**
     * 购买时装
     *
     * @param role
     * @param onlineMall
     * @param num
     * @param isGold
     * @return
     */
    private RoleEquip getCustomFashion(Role role, OnlineMall onlineMall, int num, boolean isGold) {
        RoleEquip roleEquip = new RoleEquip();
        roleEquip.setId(mallService.getRoleEquipId());
        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setPosition((short) 0);
        roleEquip.setName(onlineMall.getName());
        roleEquip.setFields(new LinkedHashMap<>());
        getCustomFashion(roleEquip, onlineMall, num, isGold);
        roleEquip.setType("时装");
        return roleEquip;
    }
    /**
     * 购买队标
     *
     * @param session
     * @param reqBuyEffect
     */
    public void buyTeamIcon(IoSession session, ReqBuyFasionTeamIcom fasionTeamIcom) {
        Role role = SessionUtils.getRoleBySession(session);
        MessagePusher.pushMessage(role,new RespNotifyMiscEx("敬请期待。"));
        return;
//        Fasion fasion = getFasionInfo(fasionTeamIcom.getName());
//        if (fasion == null) {
//            return;
//        }
//
//        String msg = "确认花费#R" + fasion.getPrice() + "#n元宝购买#R" + fasion.getName() + "#n吗？";
//        RespConfirm respConfirm = new RespConfirm();
//        respConfirm.setTips(msg);
//        MessagePusher.pushMessage(session, respConfirm);
//
//        role.setConfirm(new BuyTeamIconConfirm(fasion));
//
//        RespFasionCustomEnd respFasionCustomEnd = new RespFasionCustomEnd();
//        respFasionCustomEnd.setLabel("buy_fasion_effect");
//        MessagePusher.pushMessage(session, respFasionCustomEnd);
    }
}
